package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;

public class PactTypeActivity extends BaseActivity implements View.OnClickListener {

    String record_id;
    String pay_way;
    String cartIds;
    String type = "0";

    public void parseIntent() {
        Intent intent = getIntent();
        record_id = intent.getStringExtra("recordsId");
        pay_way = intent.getStringExtra("payType");
        cartIds = intent.getStringExtra("cartIds");
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pact_type);
        parseIntent();
        initTitle();
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("选择合同");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.clues_search).setOnClickListener(this);
        findViewById(R.id.accurate_search).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.btn_main_left:
                Intent i = new Intent();
                i.putExtra("pact", "" + type);
                setResult(RESULT_OK, i);
                finish();
                break;
            //标准合同
            case R.id.clues_search:
                startActivityForResult(StandardPactActivity.createIntent(this, record_id, pay_way, cartIds),200);
                type = "1";
                break;
            //自定义合同
            case R.id.accurate_search:
                Intent intent = new Intent(this, StandardCompactActivity.class);
                startActivityForResult(intent,300);
                type = "0";
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode==200){
            Intent i = new Intent();
            i.putExtra("pact", "1" );
            setResult(RESULT_OK, i);
            finish();
        }
        if(requestCode==300){
            Intent i = new Intent();
            i.putExtra("pact", "0" );
            setResult(RESULT_OK, i);
            finish();
        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent i = new Intent();
            i.putExtra("pact", "" + type);
            setResult(RESULT_OK, i);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
